--region *.lua
--Date
--此文件由[BabeLua]插件自动生成
local Packet = require(SCRIPTS_DIR .. ".network.Packet")
local PlayerData = class("PlayerData");

function PlayerData:ctor()
    self.uid = 0
    self.session = 0
    self.nickname = ""
    self.headimgurl = ""
    self.sex = ""
    self.propTable = {}
    self.propertyTable = {}
    self.tableId = 0
    self.hallId = 0
    self.tableStrId = ''

    self.playmodel = 0
    self.maxround = 0

    self.mails = {}
    self.lastMaildId = 0

    self.vip = 0
    self.vipExp = 0
    self.gold = 0
    self.diamond = 0
end

function PlayerData:addMail(mails)
    self:parseMail(mails)
    local str = "local mail={"
    for i,v in pairs(self.mails) do
        local tmpstr = string.format("\r\n\t\t{mailid=%d,mailtype=%d,mcindex=%d,valueitems='%s',got=%d,sendtime='%s'},",v.mailid,v.mailtype,v.mcindex,v.valueitems,v.got,v.sendtime)
        str = str .. tmpstr
    end
    str = str .. "\r\n}\r\n return mail"
    local path = device.writablePath .. "/mail.lua"
    local file = io.open(path, "wb")
    if file then
        local hr,err = file:write(str)
        if hr == nil then
            return false
        end
        io.close(file)
        return true
    else
        return false
    end
end


function PlayerData:parseMail(oldmail)
    for k,v in pairs(oldmail) do
        local newid = string.format("%d",v.mailid)
        self.mails[newid] = v
        if v.mailid > self.lastMaildId then
            self.lastMaildId = v.mailid
        end
    end
end


function PlayerData:setUid(uid)
    self.uid = uid
end

function PlayerData:getUid()
    return self.uid
end

function PlayerData:setSession(session)
    self.session = session
end

function PlayerData:getSession(session)
    return self.session
end

function PlayerData:setNickName(name)
    self.nickname = name
end

function PlayerData:getNickName()
    return self.nickname
end

function PlayerData:setHeadImgUrl(url)
    self.headimgurl = url
end

function PlayerData:getHeadImgUrl()
    return self.headimgurl
end

function PlayerData:setSex(sex)
    self.sex = sex
end

function PlayerData:getSex()
    return self.sex
end

function PlayerData:setVip(v)
    self.vip = v
    mgrs.event:dispatchEvent({name = enums.Event.VipChange});
end

function PlayerData:getVip()
    return self.vip
end

function PlayerData:setVipExp(v)
    self.vipExp = v
end

function PlayerData:getVipExp()
    return self.vipExp
end

function PlayerData:setGold(g)
    self.gold = g
    mgrs.event:dispatchEvent({name = enums.Event.GoldChange});
end

function PlayerData:getGold()
    return self.gold
end

function PlayerData:setDiamond(d)
    self.diamond = d
    mgrs.event:dispatchEvent({name = enums.Event.DiamondChange});
end

function PlayerData:getDiamond()
    return self.diamond
end

function PlayerData:addProp(propid,propcount)
    self.propTable[propid] = propcount
end

function PlayerData:getPropTable()
    return self.propTable
end

function PlayerData:setPropertyTable(propertyid,count)
    self.propertyTable[propertyid] = count
end

function PlayerData:getPropertyTable()
    return self.propertyTable
end

function PlayerData:setTableId(id)
    self.tableId = id
end

function PlayerData:getTableId()
    return self.tableId
end

function PlayerData:setHallId(id)
    self.hallId = id
end

function PlayerData:getHallId()
    return self.hallId
end

function PlayerData:setTableStrId(strId)
    self.tableStrId = strId 
end

function PlayerData:getTableStrId()
    return self.tableStrId
end

function PlayerData:setPlayModel(model)
    self.playmodel = model
end

function PlayerData:getPlayModel()
    return self.playmodel
end

function PlayerData:setMaxRound(maxround)
    self.maxround = maxround
end

function PlayerData:getMaxRound()
    return self.maxround
end

function PlayerData:getMyCard()
    -- body
    return self.propTable[1001001]
end

function PlayerData:getMyXyz()
    -- body
    return self.propertyTable[10017]
end

return PlayerData;

--endregion
